package service;

import java.sql.Time;
import java.util.Date;
import java.util.List;

import javax.inject.Inject;

import dao.TimeCardDao;
import entity.Contractor;
import entity.TimeCard;

public class ContractorService extends EmployeeService {


	public ContractorService(Contractor employee, Date lastPayDay) {
		super(new Weekly(lastPayDay), employee,lastPayDay);
	}

	@Override
	public float CalcPay() {
		Contractor employee = (Contractor) this.getEmployee();
		List<TimeCard> listTimeCard = (employee).getTimeCards();
		float pay = 0;
		if (listTimeCard != null && listTimeCard.size() != 0) {
			long diff;
			Time amount;
			for (int i = 0; i < listTimeCard.size(); i++) {
				if (this.getLastPayDay()==null||(listTimeCard.get(i).getDate().after(this.getLastPayDay()))) {
					diff = (listTimeCard.get(i).getEnd().getTime() - listTimeCard
							.get(i).getStart().getTime())
							/ (60 * 60 * 1000);
					if (diff > 8) {
						pay += (diff - 8) * 1.5 * employee.getHourly_rate() + 8
								* employee.getHourly_rate();
					} else {
						pay += diff * employee.getHourly_rate();
					}
				}
			}
		}
		return pay;
	}

}
